import 'package:car_music/src/commont/unit_bar.dart';
import 'package:car_music/src/modules/sum/my_sum_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

import '../../commont/kcontainer.dart';
import 'output_db_item.dart';

class OutputDbControl extends GetView<MySumController> {
  ///纯文字item
  Widget _textItem(String text) {
    return Expanded(
      child: Container(
        alignment: Alignment.centerRight,
        child: FittedBox(
            fit: BoxFit.scaleDown, child: Text(text, style: const TextStyle(color: Colors.white, fontSize: 12))),
      ),
    );
  }

  ///连接按钮
  Widget _list_connect() {
    return Expanded(
        child: Row(
      children: [
        Expanded(child: Container()),
        Expanded(flex: 6, child: UnitBar(title: 'DB', groupList: controller.groupList)),
        Expanded(child: Container()),
      ],
    ));
  }

  ///滑动部分
  Widget _list_slider() {
    return Expanded(
      flex: 10,
      child: Row(
        spacing: 5,
        children: [
          ///间隙
          Expanded(flex: 1, child: Container()),

          ///左边文字部分
          Expanded(
            flex: 3,
            child: Column(
              children: [
                ///间隙
                Expanded(child: Container()),

                ///间隙
                const SizedBox(height: 5),

                ///Mute
                _textItem('MUTE'),

                ///间隙
                Expanded(flex: 10, child: Container()),

                ///dB
                _textItem('dB'),

                ///间隙
                const Flexible(child: SizedBox(height: 5)),

                ///phase
                _textItem('PHASE'),
              ],
            ),
          ),

          ///中间部分
          Expanded(
            flex: 28,
            child: Obx(() {
              return Row(
                spacing: 5,
                children: globalController.rxModel.value.ch_list.map(($0) {
                  return Expanded(
                    flex: 10,
                    child: OutputDbItem(
                        model: $0,
                        onChange: (db) => controller.updateDB($0, db, needGroup: true),
                        onChangedForSend: (db) => controller.updateDB($0, db, isSend: true, needGroup: true),
                        onClick: (p0) {
                          p0 == 'MUTE'
                              ? controller.updateMUTE($0, needGroup: true)
                              : controller.updatePHASE($0, needGroup: true);
                        }),
                  );
                }).toList(),
              );
            }),
          ),

          ///右边部分
          Expanded(flex: 4, child: Container()),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return kExpanded(
      flex: 6,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          ///标题
          Expanded(
            flex: 1,
            child: Container(
                alignment: Alignment.center,
                child:
                    const Text('OUTPUT CONTROL', style: TextStyle(color: Colors.white), textAlign: TextAlign.center)),
          ),

          ///下半部分
          Expanded(
            flex: 9,
            child: Column(
              children: [
                ///🔗按钮
                _list_connect(),
                _list_slider(),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
